package com.bjqg.bjqg01.bjqg.activity.seekprice.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.BaseActivity;
import com.bjqg.bjqg01.bjqg.activity.seekprice.bean.PriceAndnameBean;
import com.bjqg.bjqg01.bjqg.adapter.LeftAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreater;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadmoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by bjqg01 on 2018/9/3.
 */

public class SeekPriceListActivity extends BaseActivity {


    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_top_title_drawer)
    TextView tvTopTitleDrawer;
    @BindView(R.id.tv_search_top_drawer)
    TextView tvSearchTopDrawer;
    @BindView(R.id.list_rlv)
    RecyclerView listRlv;
    @BindView(R.id.list_srl)
    SmartRefreshLayout listSrl;

    private RecyclerView.Adapter leftAdapter;
    List<PriceAndnameBean> list = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seekpricelist);
        ButterKnife.bind(this);
        initdate();
        initrefresh();
        initpost();
        initadapter();
    }

    private void initdate() {
        tvTopTitleDrawer.setText(getIntent().getStringExtra("name"));
        tvSearchTopDrawer.setVisibility(View.INVISIBLE);
    }


    @OnClick({R.id.back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }


    //设置上下拉刷新
    private void initrefresh() {
        SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                //全局设置主题颜色
                layout.setPrimaryColorsId(R.color.white, R.color.colorPrimary);
                //指定为经典Header，默认是 贝塞尔雷达Header
                return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
        //设置脚布局样式,全局有效
        SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter
                return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });

        listSrl.setEnableLoadmore(true);
        listSrl.setEnableLoadmoreWhenContentNotFull(true);
//        listSrl.autoRefresh();//进入界面自动刷新
        listSrl.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {//上拉

            }

            @Override
            public void onRefresh(RefreshLayout refreshlayout) {//下拉

            }
        });
    }


    private void initpost() {
        for (int i = 0; i < 20; i++) {
            String name = "通用硅酸盐水泥";
            String price = "1000";
            String number = "GB/T 2015-2005";
            list.add(new PriceAndnameBean(name, price, number));
        }
    }

    private void initadapter() {
        LinearLayoutManager leftManager = new LinearLayoutManager(this);
        leftManager.setOrientation(LinearLayoutManager.VERTICAL);
        leftAdapter = new LeftAdapter(list, this);
        listRlv.setLayoutManager(leftManager);
        listRlv.setAdapter(leftAdapter);
    }
}
